package com.practica.superTrivia;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

public class Main extends Activity {
	
	final static public int DIALOG_PLAY_INI = 1;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    /*------- Lanzamos Activities ------------------------*/ 
    public void launchPlayActivity(View view)
    {
    	showDialog(DIALOG_PLAY_INI);
    }
    
    public void launchScoresActivity(View view)
    {
    	startActivity(new Intent(Main.this, Scores.class));
    }
    
    public void launchCreditsActivity(View view)
    {
    	startActivity(new Intent(Main.this, Credits.class));
    }
    
    /*------- AlertDialogs Pool ------------------------*/
    @Override
    protected Dialog onCreateDialog(int id)
    {
        	
      	AlertDialog.Builder builder;
       	switch(id)
       	{
       	case DIALOG_PLAY_INI:
       		builder = new AlertDialog.Builder(this);
      		builder.setMessage("Are you ready?");  		
       		builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
    			
       			@Override
    			public void onClick(DialogInterface dialog, int which) {
    				
    				startActivity(new Intent(Main.this, Play.class));
    				
    			}
    			});
       		break;
       	default:
       		builder = null;
       	}
       	return builder.create();
    }
    
    /*------- Menu desplegable ------------------------*/
   	@Override
    public boolean onCreateOptionsMenu(Menu menu) { 
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.mainmenu, menu); 
      return true; 
    }    
   	
   	//Funciones de cada item del menu asociado a la actividad
   	public boolean onOptionsItemSelected (MenuItem item){

        switch (item.getItemId()){
            case R.id.menu_settings:
            	startActivity(new Intent(Main.this, Settings.class));
            return true;
            case R.id.menu_help:
            	startActivity(new Intent(Main.this, Help.class));
            return true;
            default:
            	return super.onOptionsItemSelected(item);
        }
        
   	}
}